//
// Created by sgyt on 2020/2/8.
// 使用execl执行 脚本文件
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

int main(int argc,char *argv[])
{
    int pid,res;
    pid = fork();
    if(pid < 0)
    {
        perror("fork error\n");
        exit(0);
    }else if(pid > 0)//父进程
    {
        printf("father pid = [%d],ppid = [%d]\n",getpid(),getppid());
        sleep(20);
    } else{//子进程
        printf("child pid = [%d],ppid = [%d]\n",getpid(),getppid());
        //可使用
        res = execl("/opt/shell/print.sh","print.sh","nimei","hao111","ni",NULL);
        //res = execlp("ls","ls","-al","/opt",(char *)0);
        if(res < 0)
        {
            perror("execl is error\n");
            exit(0);
        }
    }
    return 0;
}